'use strict';
/**
 * author：小小游 --- allen
 * date：2018.02.05
 * lastUpdateDate：2018.02.05
 * description：Map的基本用法
 */
/**
 * Map也实现了Iterator接口，返回了其接口的指针对象，我们同样可以
 * 使用for..of对Map数据进行遍历，下面看例子，如下：
 */
let map = new Map([
    [ 'name', 'allen' ],
    [ 'qq', '214913005' ]
]);

// console.log(map.get('name'),map.get('qq'));

// map遍历keys
for ( let keysIterator of map.keys() ) console.log(keysIterator);

console.log('----------------------------------------------------------');

// map遍历values
for ( let valuesIterator of map.values() ) console.log(valuesIterator);

console.log('----------------------------------------------------------');

// map遍历keys and values ---> entries
for ( let entriesIterator of map.entries() ) console.log(entriesIterator);

console.log('----------------------------------------------------------');

for ( let o of map ) console.log(o);

console.log('----------------------------------------------------------');

// true
console.log(Set.prototype[Symbol.iterator] === Set.prototype.values);
// false
// console.log(Map.prototype[Symbol.iterator] === Map.prototype.values);
// true
console.log(Map.prototype[Symbol.iterator] === Map.prototype.entries);

console.log('----------------------------------------------------------');

let self = {
    name : 'xiaoxiaoyou'
};

// map.forEach((k, v) => console.log(k, v));
map.forEach((k, v) => {
    console.log(self['name'], k, v);
}, self);
